package cn.darksoul3.spark.operator

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Distinct {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()
    conf.setAppName("group by key").setMaster("local[*]")

    val sc = new SparkContext(conf)

    val numbers: RDD[Int] = sc.makeRDD(List(1, 2, 1, 4, 1, 1, 1, 2, 9), numSlices = 3)
    val reduced = numbers.map((_, null)).reduceByKey((x, _) => x, numbers.getNumPartitions).map(_._1)

    println(reduced.collect().toBuffer)

  }
}
